In [1]:
#matplotlib inline

import numpy as np
import pandas as pd
import scipy.io as spio
import matplotlib.pyplot as plt

In [5]:
mat = spio.loadmat("/Volumes/Raw Data Backup/for imac/eyes/data_processing/data/bwsure1/bwsure1_proc.mat")
tg1 = mat['TG1']
tg2 = mat['TG2']
frames = mat['B'][mat['B'][:,-1] == 1]

In [6]:
frames


Out[6]:
array([[ 643629,       3,       1],
       [ 643646,       3,       1],
       [ 643679,       3,       1],
       ..., 
       [2121356,       3,       1],
       [2121389,       3,       1],
       [2121422,       3,       1]], dtype=int32)

In [7]:
tg1


Out[7]:
array([[    100,       1,  643019],
       [     50,       1,  748195],
       [    450,       1,  884837],
       [    450,       2, 1976686],
       [     50,       2, 2066063],
       [    100,       2, 2175313]], dtype=int32)

In [7]:
tg2


Out[7]:
array([[    100,       1,  695525],
       [     50,       1,  804662],
       [    450,       1,  899495],
       [    450,       2, 1993858],
       [     50,       2, 2119159],
       [    100,       2, 2234002]], dtype=int32)

In [8]:
frame_df = pd.DataFrame({'time':frames[:,0], 'press num':np.r_[0:frames.shape[0]]})

In [10]:
rad_100_2_startframe = tg1[5,2] + 612  # why add 612 to start of rad_100_2?
rad_100_2_captures = frames[(frames[:,0] >= tg1[0,2]) & (frames[:,0] <= tg2[0,2])]
rad_100_2_captures = rad_100_2_captures[:,0]
rad_100_2_captures = rad_100_2_captures - rad_100_2_captures[0] # frame offsets
rad_100_2_frames = rad_100_2_startframe + rad_100_2_captures

In [11]:
offsets = np.array([i*33 for i in xrange(1,176)])  # why do we add 175 more frame times to the end of the captures?

My guess is that there are empirically 612 ms between RADIAL_TARGET_STARTED and when frames start being captured for every other radial target phase, and that there are 175 more frames saved to rad_100_2 than rad_100_1.


In [45]:
new_captures = frame_df[(frame_df['time'] >= tg1[0,2]) & (frame_df['time'] <= tg2[0,2])].copy()
new_captures -= new_captures.iloc[0]
new_captures['press num'] += 1 + frame_df['press num'].iloc[-1]
new_captures['time'] += rad_100_2_startframe

extra_buttons = [new_captures['press num'].iloc[-1] + i for i in xrange(1,176)]
extra_frame_times = [new_captures['time'].iloc[-1] + i*33 for i in xrange(1,176)]
extra_frames = pd.DataFrame({'time':extra_frame_times, 'press num': extra_buttons})
extra_frames = extra_frames[extra_frames['time'] < tg2[5,2]]
new_captures = pd.concat([new_captures, extra_frames])
new_captures
# extra_frames


Out[45]:
press num time
0 35757 2175925
1 35758 2175942
2 35759 2175975
3 35760 2176008
4 35761 2176042
5 35762 2176075
6 35763 2176108
7 35764 2176141
8 35765 2176175
9 35766 2176208
10 35767 2176242
11 35768 2176275
12 35769 2176308
13 35770 2176341
14 35771 2176375
15 35772 2176408
16 35773 2176441
17 35774 2176475
18 35775 2176508
19 35776 2176542
20 35777 2176575
21 35778 2176608
22 35779 2176641
23 35780 2176675
24 35781 2176709
25 35782 2176742
26 35783 2176775
27 35784 2176808
28 35785 2176841
29 35786 2176875
... ... ...
145 37455 2232460
146 37456 2232493
147 37457 2232526
148 37458 2232559
149 37459 2232592
150 37460 2232625
151 37461 2232658
152 37462 2232691
153 37463 2232724
154 37464 2232757
155 37465 2232790
156 37466 2232823
157 37467 2232856
158 37468 2232889
159 37469 2232922
160 37470 2232955
161 37471 2232988
162 37472 2233021
163 37473 2233054
164 37474 2233087
165 37475 2233120
166 37476 2233153
167 37477 2233186
168 37478 2233219
169 37479 2233252
170 37480 2233285
171 37481 2233318
172 37482 2233351
173 37483 2233384
174 37484 2233417

1728 rows × 2 columns


In [44]:
more_frames = rad_100_2_frames[-1] + offsets

In [45]:
more_frames


Out[45]:
array([2227675, 2227708, 2227741, 2227774, 2227807, 2227840, 2227873,
       2227906, 2227939, 2227972, 2228005, 2228038, 2228071, 2228104,
       2228137, 2228170, 2228203, 2228236, 2228269, 2228302, 2228335,
       2228368, 2228401, 2228434, 2228467, 2228500, 2228533, 2228566,
       2228599, 2228632, 2228665, 2228698, 2228731, 2228764, 2228797,
       2228830, 2228863, 2228896, 2228929, 2228962, 2228995, 2229028,
       2229061, 2229094, 2229127, 2229160, 2229193, 2229226, 2229259,
       2229292, 2229325, 2229358, 2229391, 2229424, 2229457, 2229490,
       2229523, 2229556, 2229589, 2229622, 2229655, 2229688, 2229721,
       2229754, 2229787, 2229820, 2229853, 2229886, 2229919, 2229952,
       2229985, 2230018, 2230051, 2230084, 2230117, 2230150, 2230183,
       2230216, 2230249, 2230282, 2230315, 2230348, 2230381, 2230414,
       2230447, 2230480, 2230513, 2230546, 2230579, 2230612, 2230645,
       2230678, 2230711, 2230744, 2230777, 2230810, 2230843, 2230876,
       2230909, 2230942, 2230975, 2231008, 2231041, 2231074, 2231107,
       2231140, 2231173, 2231206, 2231239, 2231272, 2231305, 2231338,
       2231371, 2231404, 2231437, 2231470, 2231503, 2231536, 2231569,
       2231602, 2231635, 2231668, 2231701, 2231734, 2231767, 2231800,
       2231833, 2231866, 2231899, 2231932, 2231965, 2231998, 2232031,
       2232064, 2232097, 2232130, 2232163, 2232196, 2232229, 2232262,
       2232295, 2232328, 2232361, 2232394, 2232427, 2232460, 2232493,
       2232526, 2232559, 2232592, 2232625, 2232658, 2232691, 2232724,
       2232757, 2232790, 2232823, 2232856, 2232889, 2232922, 2232955,
       2232988, 2233021, 2233054, 2233087, 2233120, 2233153, 2233186,
       2233219, 2233252, 2233285, 2233318, 2233351, 2233384, 2233417])

In [62]:
rad_ind = 5
start = tg1[rad_ind,2]
end = tg2[rad_ind,2]
foi = frames[(frames[:,0] >= start) & (frames[:,0] <= end)]
foi[:,0] - start


Out[62]:
array([], dtype=int32)

In [63]:
# tkidrdp1
mat = spio.loadmat("/Volumes/Raw Data Backup/for imac/eyes/data_processing/data/tkidrdp1/tkidrdp1_proc.mat")
tg1 = mat['TG1']
tg2 = mat['TG2']
frames = mat['B'][mat['B'][:,-1] == 1]

In [64]:
tg1


Out[64]:
array([[    100,       1,  678397],
       [     50,       1,  817661],
       [    450,       1,  928030],
       [    450,       2, 1129669],
       [    100,       2, 1215029],
       [     50,       2, 1336151],
       [     50,       3, 1598616],
       [    100,       3, 1716905],
       [    200,       3, 1866315],
       [    450,       3, 1968748],
       [    450,       4, 2168330],
       [    100,       4, 2278283],
       [     50,       4, 2391324]], dtype=int32)

In [65]:
tg2


Out[65]:
array([[    100,       1,  732606],
       [     50,       1,  834048],
       [    450,       1,  943186],
       [    450,       2, 1145815],
       [    100,       2, 1273883],
       [     50,       2, 1395354],
       [     50,       3, 1653500],
       [    100,       3, 1776441],
       [    200,       3, 1909870],
       [    450,       3, 1985531],
       [    450,       4, 2184316],
       [    100,       4, 2333246],
       [     50,       4, 2407215]], dtype=int32)

In [66]:
frames


Out[66]:
array([[ 679011,       3,       1],
       [ 679028,       3,       1],
       [ 679061,       3,       1],
       ..., 
       [2186586,       3,       1],
       [2186620,       3,       1],
       [2186654,       3,       1]], dtype=int32)

In [ ]:
rad_100_4_startframe = TG1[11,2] + 612;
rad_100_4_captures = frames(frames >= TG1[0,2] & frames <= TG2[0,2]);
rad_100_4_captures = rad_100_4_captures - rad_100_4_captures[0];
rad_100_4_frames = rad_100_4_startframe + rad_100_4_captures;
for j = 1:28
    rad_100_4_frames(end+1) = rad_100_4_frames(end) + 33;
end

In [67]:
3202 + 2*(28)


Out[67]:
3258

In [68]:
(3241 - 3203) / 2.


Out[68]:
19.0

In [70]:
import yaml

In [77]:
q = yaml.load(open("/Users/bwsprague/GradSchool/Research/BerkeleyVisionStats/data/raw/gaze/tki/fixup.yaml", 'r'))

In [78]:
q


Out[78]:
[{'capture_start_offset': 612,
  'init_endtime': 732606,
  'init_starttime': 678397,
  'name': 'radial_targets_100_4',
  'num_additional_frames': 28,
  'radial_target_starttime': 2278283},
 {'capture_start_offset': 612,
  'init_endtime': 834048,
  'init_starttime': 817661,
  'last_possible_time': 2407214,
  'name': 'radial_targets_50_4',
  'num_additional_frames': 0,
  'radial_target_starttime': 2391324}]

In [79]:
q[0]


Out[79]:
{'capture_start_offset': 612,
 'init_endtime': 732606,
 'init_starttime': 678397,
 'name': 'radial_targets_100_4',
 'num_additional_frames': 28,
 'radial_target_starttime': 2278283}

In [ ]: